/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * RSInput.h
 *
 *  Created on: 2010/02/28
 *      Author: Alexandre Pires ( c.alexandre.pires@gmail.com )
 */

#ifndef RSINPUT_H_
#define RSINPUT_H_

#include "RSElement.h"

namespace Realsphere {

    class RSInput: public Realsphere::RSElement {
        Q_OBJECT
        Q_PROPERTY ( QString _attr_semantic READ SemanticTypeStr )
        Q_PROPERTY ( QString _attr_source READ Source WRITE SetSource )
        Q_PROPERTY ( int _attr_offset READ Offset WRITE SetOffset )
        Q_PROPERTY ( int _attr_set READ Set WRITE SetSet )

        public:
            Q_INVOKABLE RSInput (  Realsphere::RSInputSemanticType rSemanticType,
                                   Realsphere::RSDataSource* rSource = NULL );
            virtual ~RSInput();

        public:
            int                     Offset () const;
            RSInputSemanticType     SemanticType () const;
            RSDataSource*           SourceElement () const;
            QString                 Source () const;
            int                     Set () const;
            bool                    IsRootElement () const;

            // TODO: ELiminate this!!!
            QString                 SemanticTypeStr () const;

        public slots:
            RSError                 SetSource ( const QString& rSourceId, bool rEmit = true );
            RSError                 SetSource ( RSDataSource* rSource, bool rEmit = true );
            void                    SetOffset ( unsigned int rOffset, bool rEmit = true );
            void                    SetSet ( unsigned int rSet, bool rEmit = true );

        signals:
            void                    OffsetChanged ( int rOffset );
            void                    SourceChanged ( RSDataSource* rSourceElement );
            void                    SetChanged ( int rSet );

        public:
            static QString              InputSemanticTypeToValue ( RSInputSemanticType rSemanticType );
            static RSInputSemanticType  InputSemanticValueToType ( const QString& rTag );

        protected:
            RSError                 BeforeAddChildElement ( RSElement* rChild );

        private:
            int                     mOffset;
            RSInputSemanticType     mSemanticType;
            RSDataSource*           mSource;
            int                     mSet;
    };

}

#endif /* RSINPUT_H_ */
